package whisper.service.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import whisper.service.constants.TaskStatus;
import whisper.service.domain.db.Task;
import whisper.service.repository.TaskRepository;
import whisper.service.service.TaskService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by JT on 2018/2/24.
 */
@Service
public class TaskServiceImpl implements TaskService {

    @Autowired
    private TaskRepository taskRepository;


    @Override
    public List<Task> findTasksByStatus(TaskStatus... statusList) {
        return statusList.length == 1 ? taskRepository.findTasksByStatus(String.valueOf(statusList[0].getCode()))
                : taskRepository.findTasksByStatusList(Arrays.asList(statusList).stream()
                                .map(str -> (String.valueOf(str.getCode())))
                                .collect(Collectors.toList()));
    }

    @Override
    public void updateTaskById(Task task) {
        taskRepository.updateTaskById(task);
    }
}
